package com.edgclub.edg.activity;


import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.edgclub.edg.GuZhiApplication;
import com.edgclub.edg.R;
import com.edgclub.edg.api.CommonApi;
import com.edgclub.edg.api.ResultCode;
import com.edgclub.edg.api.param.commom.FeedBackParam;
import com.edgclub.edg.http.VolleyListener;
import com.edgclub.edg.utils.util.JSONHelper;
import com.edgclub.edg.utils.util.StringUtils;

/**
 * 意见反馈
 *
 * @author 陈坤彬
 *
 */
public class GzFeedBackActivity extends GzBaseTooolBarActivity implements View.OnClickListener , VolleyListener {

	private EditText content , account;

	private CommonApi commonApi;


	@Override
	public int getContentView() {
		return R.layout.activity_feedback;
	}

	@Override
	public void setTitleBarView() {
		setCustomActionBar();
		title.setText("意见反馈");
		main_back.setVisibility(View.VISIBLE);
		main_back.setOnClickListener(this);
		right_layout.setVisibility(View.VISIBLE);
		right_text.setText("提交");
		right_layout.setOnClickListener(this);
	}

	@Override
	public void initView() {
		content = (EditText) findViewById(R.id.content);
		account = (EditText) findViewById(R.id.account);
		commonApi = new CommonApi(this);

	}

	@Override
	public void initData() {
		commonApi = new CommonApi(this);
	}

	private void feedback() {

		if (TextUtils.isEmpty(content.getText().toString().trim())) {
			Toast.makeText(GzFeedBackActivity.this,
					StringUtils.getString(R.string.entersuggestions),
					Toast.LENGTH_LONG).show();
		} else {
			FeedBackParam param = new FeedBackParam();
			param.setUserId(GuZhiApplication.getInstance().getUserId() + "");
			param.setContent(content.getText().toString().trim());
			commonApi.feedback(param, this);

		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()){
			case R.id.main_back:
				finish();
				break;
			case R.id.right_layout:
				feedback();
				break;
		}
	}

	@Override
	public void onStart(String tag) {
		showDialog(StringUtils.getString(R.string.suggestionsing), false);
	}

	@Override
	public void onSuccess(String response, String tag) {
		dismissDialog();
		if (JSONHelper.isSuccess(response)) {
			Toast.makeText(GzFeedBackActivity.this, StringUtils.getString(R.string.suggestionssuccess),
					Toast.LENGTH_LONG).show();
			finish();
		} else {
			Toast.makeText(GzFeedBackActivity.this, StringUtils.getString(R.string.suggestionsfail),
					Toast.LENGTH_LONG).show();
		}
	}

	@Override
	public void onFaile(VolleyError volleyError, String tag) {
		dismissDialog();
		ResultCode.toastVolleyError(GzFeedBackActivity.this, volleyError);

	}



}
